<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/public/header.jsp"%>
<%
	String callback = request.getParameter("callback") == null ? "" : request.getParameter("callback");
	String type = request.getParameter("type") == null ? "" : request.getParameter("type");
	String gd_id = request.getParameter("gd_id") == null ? "" : request.getParameter("gd_id");
%>

<html>
	<head>
		<title>借料单集合选择</title>
	</head>
	<script type="text/javascript">
		$(function(){
			$("#searchValue1").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch();
		       	} 
			});
			$("#searchValue").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch();
		       	} 
			});
			$('#table').datagrid({
				title:"借料单集合选择",
				iconCls:'icon-edit',
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath %>/springMVC/gd/listPageBorrowSet?type=<%=type%>&gd_id=<%=gd_id%>',
				rownumbers:true,
				fitColumns:true,
				nowrap:false,
				idField:'borrow_detail_id',
				frozenColumns:[[
					{field:'ck',checkbox:true},
				    {title:'借料明细id',field:'borrow_detail_id',hidden:true}

				]],
				columns:[[
					{title:'借料编号',field:'borrow_code',width:80,align:'center'},
					{title:'材料id',field:'material_id',hidden:true},
					{title:'材料编号',field:'code',width:100,align:'center'},
					{title:'材料名称',field:'name',width:100,align:'center'},
					{title:'规格/型号',field:'format_type',width:150,align:'center'},
					{title:'单位',field:'unit_name',width:50,align:'center'},
					{title:'借料数量',field:'borrow_num',width:80,align:'center'}
					//{title:'已还数量',field:'already_return_num',width:80,align:'center'},
					//{title:'已还金额',field:'already_return_money',width:80,align:'center'},
// 					{title:'当前项目库数量',field:'project_num',width:100,align:'center',formatter:function(value,row,index){
// 							$.ajax({
// 								type:'POST',
// 								url:'<%=contextPath %>/springMVC/gd/getProjectMaterialNum?gd_id=<%=gd_id%>&material_id='+row.material_id,
// 								async:false,
// 								success:function(rtJson){
// 									if(rtJson == 'no'){
// 										row.project_num = '该项目库无该材料信息';
// 									}else{
// 										row.project_num = rtJson;
// 									}
// 								}
// 							});
// 							return row.project_num;
// 					}}
				]],
				toolbar:'#tb',
				pageSize:5,
				pageList : [5,50,100],  
				pagination:true,
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
		});
		
       function doSubmit(){
    	  var rows=$('#table').datagrid('getSelections');
			var ids="";
			var material_ids="";
			var operation_dates="";
			var summarys="";
			var codes="";
			var names="";
			var format_types="";
			var unit_names="";
			var borrow_nums="";
			var already_return_nums="";
			for(var i=0;i<rows.length;i++)
			{
				if(i==(rows.length-1))
				{
					ids+=rows[i].borrow_detail_id;
					material_ids+=rows[i].material_id;
					operation_dates+=rows[i].operation_date;
					summarys+=rows[i].remark;
					codes+=rows[i].code;
					names+=rows[i].name;
					format_types+=rows[i].format_type;
					unit_names+=rows[i].unit_name;
					borrow_nums+=rows[i].borrow_num;
					already_return_nums+=rows[i].already_return_num;
				}else
				{
					ids+=rows[i].borrow_detail_id+",";
					material_ids+=rows[i].material_id+",";
					operation_dates+=rows[i].operation_date+",";
					summarys+=rows[i].remark+",";
					codes+=rows[i].code+",";
					names+=rows[i].name+",";
					format_types+=rows[i].format_type+",";
					unit_names+=rows[i].unit_name+",";
					borrow_nums+=rows[i].borrow_num+",";
					already_return_nums+=rows[i].already_return_num+",";
				}
			}
			eval('window.opener.<%=callback%>(\''+ids+'\',\''+material_ids+'\',\''+operation_dates+'\',\''+summarys+'\',\''+codes+'\',\''+names+'\',\''+format_types+'\',\''+unit_names+'\',\''+borrow_nums+'\',\''+already_return_nums+'\')');
			window.close();
       }
       function doSearch(){
			var searchValue1 = $('#searchValue1').val();
			var searchValue = $('#searchValue').val();
			$('#table').datagrid('load',{
				searchValue1:searchValue1,
				searchValue:searchValue
			});
       }
		</script>
	<script type="text/javascript">
	</script>
	<body style="height: 97%">
		<div id="table" data-options="fit:true" ></div>
		<div id="tb" style="padding:3px;height:auto">
			<div style="float:left;">
				<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-save" plain="true" onclick="doSubmit;">确定</a>
			</div>
			<div align="right">
				借料编号：<input id="searchValue1" name="searchValue1" style="width:200px" title="借料编号" placeholder="借料编号"/>&nbsp;&nbsp;
				查询条件：<input id="searchValue" name="searchValue" style="width:200px" title="材料编号/材料名称" placeholder="材料编号/材料名称"/>&nbsp;&nbsp;
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
			</div>
		</div>
	</body>
</html>
